#!/bin/bash -x

BUILDCOPY_DIR="../../build_copy"

# get milestone number written by cws_get
. ./milestone
# read config
. ../../steps.config

if test -d $BUILDCOPY_DIR; then
    echo "$BUILDCOPY_DIR exists"
else
    mkdir $BUILDCOPY_DIR/
    mkdir $BUILDCOPY_DIR/Common/
    echo "Dummy" > $BUILDCOPY_DIR/Common/dummy
    echo "$BUILDCOPY_DIR dir created"
fi

# Copy necessary files and directories
$copyrecursive $BUILDCOPY_DIR/Common/* .
$copyrecursive $BUILDCOPY_DIR/${fetched_workstamp}_m$fetched_milestone/* .
$copyrecursive $BUILDCOPY_DIR/${fetched_workstamp}/m${fetched_milestone}/* .

#for name in $BUILDCOPY_DIR/${fetched_workstamp}_m$fetched_milestone/*.patch $BUILDCOPY_DIR/${fetched_workstamp}_m$fetched_milestone/*.diff
for name in *.patch *.diff
do echo patching $name
   $patch -f -p0 -F4 -N -i $name
done

#call site specific buildprep copied from build_copy
[ -f ./site_buildprep ] && . ./site_buildprep

echo do not fail on patches

